package com.taocore.top.title.action;

import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.taocore.top.title.db.DBUtils;
import com.taocore.top.title.db.Dao;

@Results({
	@Result(name="success", type="httpheader"),
	@Result(name="error", type="httpheader", params={"headers.error", "true"})
})
public class AddCustomWordAction extends ActionBase{

	static Logger _log = Logger.getLogger(AddCustomWordAction.class.getName());
	
	private String word;
	
	public String execute()
	{
		Connection conn = null;
		try
		{
			conn = DBUtils.getConnection();
			long userId = getUserId();
			Dao.INSTANCE.addCustomWords(word, userId, conn);
			return SUCCESS;
		}
		catch (Exception e) {
			_log.log(Level.SEVERE, "", e);
		}
		finally
		{
			DBUtils.close(conn, null, null);
		}
		return ERROR;
	}

	public void setWord(String word) {
		this.word = word;
	}

	public String getWord() {
		return word;
	}
}
